<?php
//防止乱码
header("content-type:text/html;charset=utf8");
//实例化
$curl=curl_init();
//地址
$url="https://www.17k.com/all";
//采集
curl_setopt($curl,CURLOPT_URL,$url);
curl_setopt($curl,CURLOPT_RETURNTRANSFER,true);
//取消ssl协议
curl_setopt($curl,CURLOPT_SSL_VERIFYPEER,false);
curl_setopt($curl,CURLOPT_SSL_VERIFYHOST,false);
//执行
$data=curl_exec($curl);
//print_r($data);
$reg='#<tr class="bg\d">.*<td class="td2">.*<a href=".*" target=".*">(.*)</a>.*</td>.*<td class="td4">.*<a href=".*" target=".*">(.*)</a>.*</td>.*<td class="td6">.*<a href=".*" target=".*" title=".*">(.*)</a>.*</td>.*<td class="td8">.*<em class="fc2">(.*)</em>.*</td>.*</tr>#isU';
preg_match_all($reg,$data,$arr);
print_r($arr);

//连接数据库
$dbh = new PDO('mysql:host=127.0.0.1;dbname=1705a', "root", "root");
//设置字符集
$dbh->exec("set names utf8");
//sql语句
$sql="insert into article (`title`,`content`,`author`,`status`) VALUES ";

$title=$arr[1];
$content=$arr[2];
$author=$arr[3];
$status=$arr[4];
foreach($title as $key=>$value){
    $sql.="('$value','$content[$key]','$author[$key]','$status[$key]'),";
}
//截取
$sql=substr($sql,0,-1);
//echo $sql;
$dbh->exec($sql);


?>